package be.vdab.Servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import be.vdab.dao.ReadSqlDAO;



/**
 * Servlet implementation class WelkomServlet
 */
@WebServlet("/welkom.htm")
public class WelkomServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String VIEW = "/WEB-INF/JSP/welkom.jsp";
	private ReadSqlDAO sqlDAO = new ReadSqlDAO();
	
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		if (session.getAttribute("destroy") == "destroy"){
			session.invalidate();
		}
		
		
		request.setAttribute("genres", sqlDAO.findGenres());
		
		if (request.getParameter("naam") != null){
			request.setAttribute("naam", request.getParameter("naam"));
			String genre = request.getParameter("naam");
			request.setAttribute("voorstellingen", sqlDAO.findVoorstellingen(genre));
		}
    	
    	RequestDispatcher dispatcher = request.getRequestDispatcher(VIEW);
	    dispatcher.forward(request, response);	
	}

}
